import api from './index'
import type { AxiosProgressEvent } from 'axios'

// 水印去除结果类型
export interface WatermarkResult {
  resultUrl: string
}

// 处理历史记录类型
export interface HistoryRecord {
  id: string
  fileName: string
  resultUrl: string
  createTime: string
}

// 历史记录响应类型
export interface HistoryResponse {
  history: HistoryRecord[]
}

/**
 * 水印去除相关API
 */
export const watermarkApi = {
  /**
   * 上传文件并去除水印
   * @param file 文件对象
   * @param onProgress 上传进度回调
   * @returns 处理结果
   */
  async removeWatermark(file: File, onProgress?: (percent: number) => void): Promise<WatermarkResult> {
    const formData = new FormData()
    formData.append('file', file)
    
    const response = await api.post<WatermarkResult>('/watermark/remove', formData, {
      onUploadProgress: (progressEvent: AxiosProgressEvent) => {
        if (progressEvent.total && onProgress) {
          const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total)
          onProgress(percent)
        }
      }
    })
    
    return response
  },
  
  /**
   * 获取处理历史
   * @returns 处理历史列表
   */
  async getHistory(): Promise<HistoryResponse> {
    const response = await api.get<HistoryResponse>('/watermark/history')
    return response
  },
  
  /**
   * 删除处理记录
   * @param id 记录ID
   * @returns 处理结果
   */
  async deleteRecord(id: string): Promise<any> {
    const response = await api.delete(`/watermark/history/${id}`)
    return response
  }
} 